﻿Imports System.Threading.Tasks

Public Class NewsControl
    Public Sub New(mw As Window1)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        Task.Factory.StartNew(Sub()
                                  LoadNews(mw)
                              End Sub)
    End Sub

    Private Sub LoadNews(mw As Window1)
        Dim entries As New List(Of NewsModel)
        Try
            Dim xml As XElement = XElement.Load("http://biller.lastelb.com/update/news.xml")
            Dim items = xml.Descendants("entry")
            For Each item In items
                Dim startdate As New Date(item.Attribute("startdate").Value)
                If Date.Now.Ticks > startdate.Ticks AndAlso Date.Now.Ticks < item.Attribute("enddate").Value Then
                    Dim temp = New NewsModel With {.Datum = startdate.ToString("dd/MM/yyyy"), .Text = item.Attribute("text")}
                    Try
                        temp.Header = item.Attribute("header").Value
                    Catch ex As Exception
                        temp.Header = ""
                    End Try
                    entries.Add(temp)
                End If
            Next
        Catch : End Try
        If entries.Count > 0 Then
            Dispatcher.BeginInvoke(Sub()
                                       newspanel.ItemsSource = entries
                                       mw.AddNewWelcomeInfo(Me)
                                   End Sub)
        End If
    End Sub
End Class

Public Class NewsModel
    Public Property Header As String
    Public Property Datum As String
    Public Property Text As String
End Class
